{
 "cells": [
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "def calculate_bmi(weight, height):\n",
    "    \"\"\"计算BMI指数\"\"\"\n",
    "    bmi = weight / (height ** 2)\n",
    "    return bmi\n",
    "\n",
    "def classify_bmi(bmi):\n",
    "    \"\"\"根据BMI指数进行分类\"\"\"\n",
    "    if bmi < 18.5:\n",
    "        return \"体重过轻\"\n",
    "    elif 18.5 <= bmi < 24:\n",
    "        return \"正常体重\"\n",
    "    elif 24 <= bmi < 28:\n",
    "        return \"超重\"\n",
    "    else:\n",
    "        return \"肥胖\"\n",
    "\n",
    "# 获取用户输入的身高和体重\n",
    "weight = float(input(\"请输入体重（公斤）：\"))\n",
    "height = float(input(\"请输入身高（米）：\"))\n",
    "\n",
    "# 计算BMI\n",
    "bmi = calculate_bmi(weight, height)\n",
    "\n",
    "# 对BMI进行分类\n",
    "classification = classify_bmi(bmi)\n",
    "\n",
    "# 输出结果\n",
    "print(f\"您的BMI指数为：{bmi:.2f}\")\n",
    "print(f\"您的身体质量分类为：{classification}\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-05-23T07:31:42.455069Z"
    }
   },
   "id": "9adec24ff82e1ae2",
   "execution_count": null
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "def calculate_bmi(weight, height):\n",
    "    \"\"\"计算BMI指数\"\"\"\n",
    "    bmi = weight / (height ** 2)\n",
    "    return bmi\n",
    "\n",
    "def classify_bmi_china(bmi):\n",
    "    \"\"\"根据BMI指数进行中国分类\"\"\"\n",
    "    if bmi < 18.5:\n",
    "        return \"体重过轻\"\n",
    "    elif 18.5 <= bmi < 24:\n",
    "        return \"正常体重\"\n",
    "    elif 24 <= bmi < 28:\n",
    "        return \"超重\"\n",
    "    else:\n",
    "        return \"肥胖\"\n",
    "\n",
    "def classify_bmi_world(bmi):\n",
    "    \"\"\"根据BMI指数进行国际分类\"\"\"\n",
    "    if bmi < 18.5:\n",
    "        return \"体重过轻\"\n",
    "    elif 18.5 <= bmi < 25:\n",
    "        return \"正常体重\"\n",
    "    elif 25 <= bmi < 30:\n",
    "        return \"超重\"\n",
    "    else:\n",
    "        return \"肥胖\"\n",
    "\n",
    "# 获取用户输入的身高和体重\n",
    "weight = float(input(\"请输入体重（公斤）：\"))\n",
    "height = float(input(\"请输入身高（米）：\"))\n",
    "\n",
    "# 计算BMI\n",
    "bmi = calculate_bmi(weight, height)\n",
    "\n",
    "# 对BMI进行国内和国际分类\n",
    "classification_china = classify_bmi_china(bmi)\n",
    "classification_world = classify_bmi_world(bmi)\n",
    "\n",
    "# 输出结果\n",
    "print(f\"您的BMI指数为：{bmi:.2f}\")\n",
    "print(f\"根据中国标准，您的身体质量分类为：{classification_china}\")\n",
    "print(f\"根据国际标准，您的身体质量分类为：{classification_world}\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-05-23T07:31:42.456497Z"
    }
   },
   "id": "47ff6d462bf9864",
   "execution_count": null
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "def calculate_bmi(weight, height):\n",
    "    \"\"\"计算BMI指数\"\"\"\n",
    "    bmi = weight / (height ** 2)\n",
    "    return bmi\n",
    "\n",
    "def classify_bmi_china(bmi):\n",
    "    \"\"\"根据BMI指数进行中国分类\"\"\"\n",
    "    if bmi < 18.5:\n",
    "        return \"体重过轻\"\n",
    "    elif 18.5 <= bmi < 28:\n",
    "        return \"正常体重\"\n",
    "    else:\n",
    "        return \"超重\"\n",
    "\n",
    "def classify_bmi_world(bmi):\n",
    "    \"\"\"根据BMI指数进行国际分类\"\"\"\n",
    "    if bmi < 18.5:\n",
    "        return \"体重过轻\"\n",
    "    elif 18.5 <= bmi < 25:\n",
    "        return \"正常体重\"\n",
    "    elif 25 <= bmi < 30:\n",
    "        return \"超重\"\n",
    "    else:\n",
    "        return \"肥胖\"\n",
    "\n",
    "def main():\n",
    "    while True:\n",
    "        # 获取用户输入的身高和体重\n",
    "        try:\n",
    "            weight = float(input(\"请输入体重（公斤）：\"))\n",
    "            height = float(input(\"请输入身高（米）：\"))\n",
    "        except ValueError:\n",
    "            print(\"输入错误，请输入有效的数字。\")\n",
    "            continue\n",
    "\n",
    "        # 计算BMI\n",
    "        bmi = calculate_bmi(weight, height)\n",
    "\n",
    "        # 对BMI进行国内和国际分类\n",
    "        classification_china = classify_bmi_china(bmi)\n",
    "        classification_world = classify_bmi_world(bmi)\n",
    "\n",
    "        # 输出结果\n",
    "        print(f\"您的BMI指数为：{bmi:.2f}\")\n",
    "        print(f\"根据中国标准，您的身体质量分类为：{classification_china}\")\n",
    "        print(f\"根据国际标准，您的身体质量分类为：{classification_world}\\n\")\n",
    "\n",
    "        # 询问用户是否继续\n",
    "        continue_prompt = input(\"是否继续计算另一位的BMI？(输入'y'继续，其他任意键退出)：\")\n",
    "        if continue_prompt.lower() != 'y':\n",
    "            break\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    main()"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "125f148aaa03b415",
   "execution_count": null
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "def calculate_bmi(weight, height):\n",
    "    \"\"\"计算BMI指数\"\"\"\n",
    "    bmi = weight / (height ** 2)\n",
    "    return bmi\n",
    "\n",
    "def classify_bmi_china(bmi):\n",
    "    \"\"\"根据BMI指数进行中国分类\"\"\"\n",
    "    if bmi < 18.5:\n",
    "        return \"体重过轻\"\n",
    "    elif 18.5 <= bmi < 28:\n",
    "        return \"正常体重\"\n",
    "    else:\n",
    "        return \"超重\"\n",
    "\n",
    "def classify_bmi_world(bmi):\n",
    "    \"\"\"根据BMI指数进行国际分类\"\"\"\n",
    "    if bmi < 18.5:\n",
    "        return \"体重过轻\"\n",
    "    elif 18.5 <= bmi < 25:\n",
    "        return \"正常体重\"\n",
    "    elif 25 <= bmi < 30:\n",
    "        return \"超重\"\n",
    "    else:\n",
    "        return \"肥胖\"\n",
    "\n",
    "def main():\n",
    "    person_count = 0\n",
    "    max_persons = int(input(\"请输入您想计算BMI的人数：\"))\n",
    "\n",
    "    for _ in range(max_persons):\n",
    "        try:\n",
    "            weight = float(input(f\"请输入第{person_count + 1}个人的体重（公斤）：\"))\n",
    "            height = float(input(f\"请输入第{person_count + 1}个人的身高（米）：\"))\n",
    "            person_count += 1\n",
    "        except ValueError:\n",
    "            print(\"输入错误，请输入有效的数字。\")\n",
    "            continue\n",
    "\n",
    "        bmi = calculate_bmi(weight, height)\n",
    "        classification_china = classify_bmi_china(bmi)\n",
    "        classification_world = classify_bmi_world(bmi)\n",
    "\n",
    "        print(f\"第{person_count}人的BMI指数为：{bmi:.2f}\")\n",
    "        print(f\"根据中国标准，身体质量分类为：{classification_china}\")\n",
    "        print(f\"根据国际标准，身体质量分类为：{classification_world}\\n\")\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    main()"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "467dd3138c112554"
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<string>, line 0)",
     "output_type": "error",
     "traceback": [
      "Traceback \u001B[1;36m(most recent call last)\u001B[0m:\n",
      "\u001B[0m  File \u001B[0;32m~\\PycharmProjects\\pythonProject1\\.venv\\Lib\\site-packages\\IPython\\core\\interactiveshell.py:3577\u001B[0m in \u001B[0;35mrun_code\u001B[0m\n    exec(code_obj, self.user_global_ns, self.user_ns)\u001B[0m\n",
      "\u001B[1;36m  Cell \u001B[1;32mIn[9], line 1\u001B[1;36m\n\u001B[1;33m    gender, age = eval(input())\u001B[1;36m\n",
      "\u001B[1;36m  File \u001B[1;32m<string>\u001B[1;36m\u001B[0m\n\u001B[1;33m    \u001B[0m\n\u001B[1;37m    ^\u001B[0m\n\u001B[1;31mSyntaxError\u001B[0m\u001B[1;31m:\u001B[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "gender, age = eval(input())\n",
    "if ((gender == 1 and age > 60) or (gender == 0 and age > 55)):\n",
    "    print(\"退休\")\n",
    "else:\n",
    "    print(\"不退休\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-05-23T07:31:42.455069Z",
     "start_time": "2024-05-23T07:31:40.490449Z"
    }
   },
   "id": "421ccf8b84850561",
   "execution_count": 9
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "#CalBMIv3.py\n",
    "height, weight = eval(input(\"输入身高(米)和体重(公斤)[逗号隔开]: \"))\n",
    "bmi = weight / pow(height, 2)\n",
    "print(\"BMI 数值为：{:.2f}\".format(bmi))\n",
    "who, nat = \"\", \"\"\n",
    "if bmi < 18.5:\n",
    "    who, nat = \"偏瘦\", \"偏瘦\"\n",
    "elif 18.5 <= bmi < 24:\n",
    "    who, nat = \"正常\", \"正常\"\n",
    "elif 24 <= bmi < 25:\n",
    "    who, nat = \"正常\", \"偏胖\"\n",
    "elif 25 <= bmi < 28:\n",
    "    who, nat = \"偏胖\", \"偏胖\"\n",
    "elif 28 <= bmi < 30:\n",
    "    who, nat = \"偏胖\", \"肥胖\"\n",
    "else:\n",
    "    who, nat = \"肥胖\", \"肥胖\"\n",
    "print(\"BMI 指标为:国际'{0}', 国内'{1}'\".format(who, nat))"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "b15a5e48a320f80f"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
